package org.ilead.iserve.common.email;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;


public class RegisterEmailTemplate{
	public final static String TITLE = "${loginName},请激活你的LOP网站帐户";
	
	public static String CONTENT = "<br><font size=\"2\">感谢您注册LOP网站</font><br><br>" +
			"<font size=\"3\">请点击下面的链接激活您的帐户</font><br>" +
			"<a href=\"http://${WebUrl}/verify.action?id=${id}&code=${code}\">http://${WebUrl}/verify.action?id=${id}&code=${code}</a><br>";
	private static boolean hasInit = false;
	
	private static void init(){
		ActionContext ctx = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
		if(request != null){
			String serverName = request.getServerName();
			int serverPort = request.getServerPort();
			String contextPath = request.getContextPath();
			String webUrl = serverName + (serverPort == 80 ? "" : ":" + serverPort) + contextPath;
			CONTENT = CONTENT.replace("${WebUrl}", webUrl);
			hasInit = true;
		}
	}
	
	public static String getTitle(String loginName) {
		return TITLE.replace("${loginName}", loginName);
	}

	public static String getContent(String id,String code) {
		if(!hasInit)
			init();
		return CONTENT.replace("${id}", id).replace("${code}", code);
	}

}
